home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / utility / uwserver.zip / uwserver.tar / misc / macmouse.ml < prev    next >
Lisp/Scheme  |  1991-01-25  |  8KB  |  364 lines

  1. ; $Header: /c/cak/lib/mlisp/RCS/macmouse.ml,v 1.5 85/11/05 14:01:44 cak Rel $
  2. ; Macintosh mouse routines for use with John Bruner's uw program.
  3. ;     Chris Kent, Purdue University Fri Oct 25 1985
  4. ;     Copyright 1985 by Christopher A. Kent. All rights reserved.
  5. ;     Permission to copy is given provided that the copy is not
  6. ;     sold and this copyright notice is included.
  7. ; Provides a scroll bar/thumbing area in the unused scroll bar with the
  8. ; following features:
  9. ;     click at line 1 does previous page
  10. ;    click at line 24 does next page
  11. ;     click anywhere else "thumbs" to the relative portion of the buffer.
  12. ;     shift-click at line 1 scrolls one line down
  13. ;     shift-click at line 24 scrolls one line up
  14. ;     shift-click elsewhere moves line to top of window
  15. ;     option-shift-click elsewhere moves line to bottom of window
  16. ; There is also basic positioning and kill-buffer support:
  17. ;     click in a buffer moves dot there
  18. ;     drag copies the dragged region to the kill buffer (mark is left
  19. ;         at the beginning of the region.)
  20. ;     shift-drag deletes the dragged region to the kill buffer
  21. ;   it is possible to use the scrolling and thumbing area to make the region
  22. ;   larger than a single screen; just click, scroll, release. Make sure
  23. ;   that the last scroll is just a down event; the up must be in the buffer.
  24. ;
  25. ;     option-click yanks from the kill buffer, doesn't affect mark.
  26. ;     option-shift-click similarly yanks from a named buffer.
  27.  
  28. (declare-global
  29.     #mouse-last-x        ; x of last event
  30.     #mouse-last-y        ; y of last event
  31.     #mouse-last-b        ; buttons at last event
  32.     #mouse-last-dot        ; dot after last event
  33.     #mouse-last-action        ; whether last was scroll (1) or edit (2)
  34. )
  35.  
  36. (defun
  37.     (move-mac-cursor savest b x y up down lock shift option command saveb
  38.     (setq savest stack-trace-on-error)
  39.     (setq stack-trace-on-error 0)
  40.     ; decode everything
  41.     (setq y (- (get-tty-character) 32))
  42.     (setq x (- (get-tty-character) 32))
  43.     (setq b (- (get-tty-character) 32))
  44.     (setq saveb b)
  45.     (setq command (% b 2))(setq b (/ b 2))    ; command key
  46.     (setq shift (% b 2))(setq b (/ b 2))    ; shift 
  47.     (setq lock (% b 2))(setq b (/ b 2))    ; caps-lock
  48.     (setq option (% b 2))(setq b (/ b 2))    ; option
  49.     (setq down (% b 2))(setq b (/ b 2))    ; mouse down
  50.     (setq up (% b 2))
  51.     
  52.     (if (= x 81)        ; right margin -- move-dot-to-x-y is wrong
  53.         (progn 
  54.            (#mouse-scroll-region)
  55.            (setq #mouse-last-action 1))
  56.         (if (error-occurred 
  57.             (if (= #mouse-last-action 2)    ; not if just scrolled
  58.             (setq #mouse-last-dot (dot)))
  59.             (move-dot-to-x-y x y)
  60.             (backward-character)(forward-character)
  61.             (#mouse-edit-action)
  62.             (setq #mouse-last-action 2)
  63.         )
  64.         (progn 
  65.                (#mouse-scroll-region b x y)
  66.                (setq #mouse-last-action 1))
  67.         ))
  68.     (setq stack-trace-on-error savest)
  69.     (if (= down 1)
  70.         (progn 
  71.            (setq #mouse-last-x x)
  72.            (setq #mouse-last-y y)
  73.            (setq #mouse-last-b saveb))
  74.         (progn 
  75.            (setq #mouse-last-x 0)
  76.            (setq #mouse-last-y 0)
  77.            (setq #mouse-last-b 0)))
  78.     )
  79.     
  80.     (#mouse-edit-action        ; marking and editing actions on buttons:
  81.                 ;   if no movement, nothing.
  82.                 ;   if movement, put  mark at #mouse-last-dot,
  83.                 ;      leave dot here,and edit.
  84.                 ; editing (on upstrokes):
  85.                 ;   unmodified, copy to kill buffer.
  86.                 ;   SHIFTed, delete (cut) to kill buffer.
  87.                 ; 
  88.                 ; option-click yanks from kill buffer; 
  89.                 ; shift-option-click from named buffer.
  90.     (if (= saveb 16)
  91.         (#mouse-d))
  92.     (if (= saveb 17)
  93.         (#mouse-dc))
  94.     (if (= saveb 18)
  95.         (#mouse-ds))
  96.     (if (= saveb 19)
  97.         (#mouse-dsc))
  98.     (if (= saveb 20)
  99.         (#mouse-dl))
  100.     (if (= saveb 21)
  101.         (#mouse-dlc))
  102.     (if (= saveb 22)
  103.         (#mouse-dls))
  104.     (if (= saveb 23)
  105.         (#mouse-dlsc))
  106.     (if (= saveb 24)
  107.         (#mouse-do))
  108.     (if (= saveb 25)
  109.         (#mouse-doc))
  110.     (if (= saveb 26)
  111.         (#mouse-dos))
  112.     (if (= saveb 27)
  113.         (#mouse-dosc))
  114.     (if (= saveb 28)
  115.         (#mouse-dol))
  116.     (if (= saveb 29)
  117.         (#mouse-dolc))
  118.     (if (= saveb 30)
  119.         (#mouse-dols))
  120.     (if (= saveb 31)
  121.         (#mouse-dolsc))
  122.     (if (= saveb 32)
  123.         (#mouse-u))
  124.     (if (= saveb 33)
  125.         (#mouse-uc))
  126.     (if (= saveb 34)
  127.         (#mouse-us))
  128.     (if (= saveb 35)
  129.         (#mouse-usc))
  130.     (if (= saveb 36)
  131.         (#mouse-ul))
  132.     (if (= saveb 37)
  133.         (#mouse-ulc))
  134.     (if (= saveb 38)
  135.         (#mouse-uls))
  136.     (if (= saveb 39)
  137.         (#mouse-ulsc))
  138.     (if (= saveb 40)
  139.         (#mouse-uo))
  140.     (if (= saveb 41)
  141.         (#mouse-uoc))
  142.     (if (= saveb 42)
  143.         (#mouse-uos))
  144.     (if (= saveb 43)
  145.         (#mouse-uosc))
  146.     (if (= saveb 44)
  147.         (#mouse-uol))
  148.     (if (= saveb 45)
  149.         (#mouse-uolc))
  150.     (if (= saveb 46)
  151.         (#mouse-uols))
  152.     (if (= saveb 47)
  153.         (#mouse-uolsc))
  154.     )
  155.  
  156.     ; individual button bindings
  157.  
  158.     (#mouse-u            ; up
  159.          (if (! (#mouse-click-p))
  160.         (progn 
  161.            (#mouse-set-region)
  162.            (Copy-region-to-kill-buffer)
  163.         ))
  164.     )
  165.  
  166.     (#mouse-uc            ; up/command
  167.     )
  168.  
  169.     (#mouse-us            ; up/shift
  170.          (if (! (#mouse-click-p))
  171.         (progn 
  172.            (#mouse-set-region)
  173.            (delete-to-killbuffer)
  174.         ))
  175.     )
  176.  
  177.     (#mouse-usc            ; up/shift/command
  178.     )
  179.  
  180.     (#mouse-ul            ; up/lock
  181.     )
  182.  
  183.     (#mouse-ulc            ; up/lock/command
  184.     )
  185.  
  186.     (#mouse-uls            ; up/lock/shift
  187.     )
  188.  
  189.     (#mouse-ulsc        ; up/lock/shift/command
  190.     )
  191.  
  192.     (#mouse-uo            ; up/option
  193.          (if (#mouse-click-p)
  194.         (yank-from-killbuffer)
  195.     )
  196.     )
  197.  
  198.     (#mouse-uoc            ; up/option/command
  199.     )
  200.  
  201.     (#mouse-uos            ; up/option/shift
  202.     (if (#mouse-click-p)    ; click
  203.         (yank-buffer (get-tty-buffer "Insert contents of buffer: "))
  204.     )
  205.     )
  206.  
  207.     (#mouse-uosc        ; up/option/shift
  208.     )
  209.  
  210.     (#mouse-uol            ; up/option/lock
  211.     )
  212.  
  213.     (#mouse-uolc        ; up/option/lock
  214.     )
  215.  
  216.     (#mouse-uols        ; up/option/lock/shift
  217.     )
  218.  
  219.     (#mouse-uolsc        ; up/option/lock/shift/command
  220.     )
  221.     
  222.     (#mouse-d            ; down
  223.     )
  224.  
  225.     (#mouse-dc            ; down/command
  226.     )
  227.  
  228.     (#mouse-ds            ; down/shift
  229.     )
  230.  
  231.     (#mouse-dsc            ; down/shift/command
  232.     )
  233.  
  234.     (#mouse-dl            ; down/lock
  235.     )
  236.  
  237.     (#mouse-dlc            ; down/lock/command
  238.     )
  239.  
  240.     (#mouse-dls            ; down/lock/shift
  241.     )
  242.  
  243.     (#mouse-dlsc        ; down/lock/shift/command
  244.     )
  245.  
  246.     (#mouse-do            ; down/option
  247.     )
  248.  
  249.     (#mouse-doc            ; down/option/command
  250.     )
  251.  
  252.     (#mouse-dos            ; down/option/shift
  253.     )
  254.  
  255.     (#mouse-dosc        ; down/option/shift
  256.     )
  257.  
  258.     (#mouse-dol            ; down/option/lock
  259.     )
  260.  
  261.     (#mouse-dolc        ; down/option/lock
  262.     )
  263.  
  264.     (#mouse-dols        ; down/option/lock/shift
  265.     )
  266.  
  267.     (#mouse-dolsc        ; down/option/lock/shift/command
  268.     )
  269.  
  270.     (#mouse-set-region        ; set the region to be from last dot to dot.
  271.     (set-mark)
  272.     (goto-character #mouse-last-dot)
  273.     (exchange-dot-and-mark)
  274.     )
  275.  
  276.     (#mouse-click-p clickp
  277.          (if (= (dot) #mouse-last-dot)
  278.         (setq clickp 1)
  279.         (setq clickp 0)
  280.     ))
  281.     
  282.     (#mouse-scroll-region     ; out of range actions:
  283.                 ;    left margin -- hard to generate, ignored
  284.                 ;    right margin -- simulate scroll bar
  285.                 ;      line 1 -- previous page
  286.                 ;      line 24/25 -- next page
  287.                 ;      other lines -- thumbing
  288.                 ;    top margin -- previous page
  289.                 ;    bottom margin -- next page
  290.                 ; 
  291.                 ; if shifted, deal with lines. 
  292.                 ;    line 1 scrolls one line down
  293.                 ;    line 24/25 scrolls one line up
  294.                 ;    else line to top;  with option to bottom.
  295.                 ;
  296.                 ; if up stroke is in same place as down
  297.                 ; stroke, don't do anything, so clicks in
  298.                 ; the scroll region don't do the action
  299.                 ; twice.
  300.     (if (= down 1)
  301.         (if (= shift 1)
  302.         (do-lines)
  303.         (do-pages))
  304.     )
  305.     (if (& (= up 1)
  306.            (| (!= x #mouse-last-x) (!= y #mouse-last-y)))
  307.         (if (= shift 1)
  308.         (do-lines)
  309.         (do-pages)
  310.         )
  311.     )
  312.     (#mouse-set-region)
  313.     )
  314.  
  315.     (do-pages            ; large motions via pages and thumbing
  316.     (if (| (= y 0) (= y 1) (= y 24) (= y 25))
  317.         (progn 
  318.            (if (| (= y 0) (= y 1))
  319.                (previous-page)
  320.                (Next-Page)
  321.            ))
  322.         (if (= x 81)
  323.         (goto-percent (/ (* y 100) 25))
  324.         )
  325.     ))
  326.  
  327.     (do-lines            ; fine control over lines
  328.     (if (= x 81)
  329.         (if (| (= y 1) (= y 24) (= y 25))
  330.         (if (| (= y 0) (= y 1))
  331.             (scroll-one-line-down)
  332.             (scroll-one-line-up)
  333.         )
  334.         (progn
  335.               (move-dot-to-x-y 1 y)
  336.               (if (= option 0)
  337.               (line-to-top-of-window)
  338.               (line-to-bottom-of-window))
  339.         )
  340.         )
  341.     )
  342.     )
  343.  
  344.     (line-to-bottom-of-window nlines i
  345.     (line-to-top-of-window)
  346.     (setq i 0)
  347.     (setq nlines (- (window-height) 1))
  348.     (while (< i nlines)
  349.            (scroll-one-line-down)
  350.            (setq i (+ i 1))
  351.     )
  352.     )
  353.  
  354.     (goto-percent
  355.        (goto-character (/ (* (buffer-size) (arg 1)) 100))
  356.    )
  357. )
  358.     
  359. (bind-to-key "move-mac-cursor" "\em")
  360.